<?php 
$url = $this->baseUrl();
$storage = new Zend_Auth_Storage_Session();
$data = $storage->read();

?>
<?php if($this->countChanel > 1):?>
<div class="post-content clearfix" style="margin-bottom: 20px;">
	<div class="post-text" style="padding: 0;width: 598px;">
	<h4 style="color: #db5c56;margin-left: 20px;">Danh sách những channel mà bạn có thể kết nối:</h4>
	<iframe width="100%" height="200" style="border: 0;" src="<?php echo $url;?>/chanel/list/"></iframe>
	</div>
</div>
<?php endif;?>

<?php if($data):?>

<div class="post-content clearfix">
		
		<div class="avatar_and_i">
		
			<?php if($data->avatar):?>
			
				<img alt="noavatar" class="post_avatar"   src="<?php echo $url;?>/upload/<?php echo $data->avatar ;?>">
				
			<?php else :?>
			
				<img alt="noavatar" class="post_avatar"   src="http://0.gravatar.com/avatar/98d7a2361501957b551a32fceca493a5?s=56&d=mm&r=G">
				
			<?php endif;?>
		
		</div>
		
		<form enctype="multipart/form-data" name="uploadmedia" id="myForm" method="POST" action="<?php echo $url;?>/post/index/ajaxupload">		
		<div class="post-text" style="padding: 0;width: 598px;">

			<input type="hidden" name="title" value="">
			<input type="hidden" name="idcategory" value="">
			
			<div id="placeholder" style="width:85%; height30px; position: absolute; top: 43px;z-index: 1;left: 110px; color: #555">Suy nghĩ của bạn?</div>

			<textarea id="editor" name="content" ></textarea>
			
			 <label id="camera" class="ipt-form-upload-label" data-title="Insert Media" data-delay="{ show: 500, hide: 100 }" data-placement="bottom" >

                   <span>Add Photo</span>

                   <span><input type="file" multiple="multiple" id="myfile" name="myfile[]"  /></span>

                   <div class="clearfix"></div>
                   
              </label>
              
              <div id="media">
              		
              </div>
              
              <div id="wait" style="text-align: center;display: none;">
              			<img alt="wait" src="<?php echo $this->dirImg;?>/ajax-loader.gif">
              </div>
              
              <input type="hidden" name="idchanel" value="" />
              <input id="hd_post" type="hidden" name="module" value ="preview">
              <input type="hidden" name="user_wall_id" value ="<?php echo $this->user_wall_id;?>" >
              <input class="btn btn-success" style="margin: 5px;" id="btn-publish" type="button" value ="Post"/>
		
		</div>
		</form>
</div>

<?php endif;?>


<div id="main-post">

<?php foreach($this->posts as $key => $val):?>
<?php $list = $this->media->listItemByPost($val["id"]);?>

<?php if($data):?>
	

	<?php $this->post->updateFeed($val); ?>

<?php endif;?>

<div id="post<?php echo $val["id"]?>" class="post">

	<form method="post" id="editpost<?php echo $val["id"]?>">
		<input type="hidden" name="module" value ="edit">
		<input type="hidden" name="idpost" value ="<?php echo $val["id"];?>">
	</form>
	
	<?php if($data && $data->id == $val["userid"]):?>
	
	<div id="edit-post<?php echo $val["id"]?>" class="edit-post">
		<a href="javascript:void(0);" onclick="onEditPost('editpost<?php echo $val["id"]?>');">Edit</a> | <a href="javascript:void(0);" onclick="onDeletePost('<?php echo $val["id"];?>');">Delete</a>
	</div>
	<?php endif;?>
	<script type="text/javascript">

         $(document).ready(function(){
            $('#post<?php echo $val["id"]?>').hover(function() {

            $("#edit-post<?php echo $val["id"]?>").css("visibility","visible");
          }, function() {
            $("#edit-post<?php echo $val["id"]?>").css("visibility","hidden");
           });
         });
     </script>
	

	<div class="post-content clearfix">
		
		<div class="avatar_and_i">
		
			<?php $user = $this->auth->getItemByComment($val["userid"]);?>
			
			<a href="<?php echo $url;?>/post/?id=<?php echo $user["id"];?>" target="_blank">
		
				<?php if($user["avatar"] != ""):?>	
				
					<img alt="noavatar" class="post_avatar"   src="<?php echo $url;?>/upload/<?php echo $user["avatar"];?>">
					
				<?php else :?>
					<img alt="noavatar" class="post_avatar"   src="http://0.gravatar.com/avatar/98d7a2361501957b551a32fceca493a5?s=56&d=mm&r=G">
				<?php endif;?>
			
			</a>
			
		
		</div>
				
		<div class="post-text" >
		
				<a class="post_info" href="<?php echo $url;?>/post/?id=<?php echo $user["id"];?>"><?php echo $user["displayname"]?></a>
				
				<?php if($val["chanelid"]!=""):?>
					
					<?php $chanel = $this->post->getChanelByPost($val["chanelid"]);?>
					
					<?php if($chanel):?>
					
						<a href="#"><img src="<?php echo $this->dirImg;?>/arrow.png " /></a>
						<a class="post_info" href="<?php echo $url;?>/chanel/?id=<?php echo $chanel["id"];?>"><?php echo $chanel["name"];?></a>
					
					<?php endif;?>
					
					
				<?php else:?>
				
					<?php if($val["user_wall_id"]):?>
					
						<?php $userpost = $this->post->getUserByPost($val["user_wall_id"]);?>
						
						<?php if($userpost):?>
						
							<a href="#"><img src="<?php echo $this->dirImg;?>/arrow.png " /></a>						
							<a class="post_info" href="<?php echo $url;?>/post/?id=<?php echo $userpost["id"];?>"><?php echo $userpost["displayname"];?></a>
							
						<?php endif;?>
						
					<?php endif;?>
				
				<?php endif;?>
				
				<?php if ($data == FALSE || ($data && $this->follow->ischeckFollow($val["userid"],$data->id) == 0 && $data->id != $val["userid"])):?>
				
				<a id="btn-follow-friend<?php echo $val["id"];?>" href="javascript:void(0);" class="reblog_follow_button" style="color: #fff; font-size: 11px;line-height: 16px;" data-tumblelog-name="<?php echo $user["displayname"]?>" title="Kết nối <?php echo $user["displayname"]?>" onclick="<?php if($data):?>followFriend('<?php echo $val["id"];?>');<?php else:?> login();<?php endif;?>><i>Kết nối</i></a>
				
				<?php endif;?>
				
				<h3 style="text-indent: 0px; margin-top: 0px;">
				
				<a style="font-size: 18px; color: #333;" href="<?php echo $this->post->getLink($url,$val); ?>" <?php if ($val["type"]== "rss"):?>target="_blank"<?php endif;?>><?php echo $val["title"];?></a>
				
				</h3>
				
				
				<p class="post-meta" style="text-indent: 0px;"></p>
				
				
				
				<p><?php echo $val["content"];?></p>
				
				
				<div class="info-panel">
		
		<?php if($list):?>
		
			
		
			<div class="single-thumb" id="content<?php echo $val['id'];?>">
				
					<div id="msg_slideshow<?php echo $val['id'];?>" class="msg_slideshow">
					
					<?php foreach( $list as $key => $item):?>
			
						<?php if ($val["type"] == "rss"):?>
							<?php $media_link = $item['link']?> 
						<?php else :?>
							<?php $media_link = $url."/upload/".$item['link']?>
						<?php endif;?>
					
					    <a id="msg_wrapper<?php echo $val['id'];?>" class="msg_wrapper cloud-zoom" rev="group<?php echo $val['id'];?>" rel="zoomHeight:200, zoomWidth:400, adjustX: 10, adjustY:-4, position:'body'"  href="<?php echo $media_link;?>">
					    
					    </a>
					    
					<?php endforeach;?>
					
					
					    
					    <div id="msg_controls<?php echo $val['id'];?>" class="msg_controls" style="width: 80px;">
					        
					        <a href="#" id="msg_prev<?php echo $val['id'];?>" class="msg_prev prev"></a>
					        <a href="#" id="msg_pause_play<?php echo $val['id'];?>" class="msg_pause"></a>
					        <a href="#" id="msg_next<?php echo $val['id'];?>" class="msg_next next"></a>
					    </div>
					    <div id="msg_thumbs<?php echo $val['id'];?>" class="msg_thumbs">
					        <div class="msg_thumb_wrapper">
					        
					        
					        <?php foreach($list as $key => $item):?>
					    		<?php if ($val["type"] == "rss"):?>
									<?php $media_link = $item['link']?> 
								<?php else :?>
									<?php $media_link = $url."/upload/".$item['link']?>
								<?php endif;?>
					    		<a href="#">
					    		
					    			<img src="<?php echo $media_link; ?>" alt="<?php echo $media_link; ?>"/>
					    			
					    		</a>
					    
							<?php endforeach;?>
					        
					        </div>
					        
					        <a href="#" id="msg_thumb_next<?php echo $val['id'];?>" class="msg_thumb_next next"></a>
					        <a href="#" id="msg_thumb_prev<?php echo $val['id'];?>" class="msg_thumb_prev prev"></a>
					        <a href="#" id="msg_thumb_close<?php echo $val['id'];?>" class="msg_thumb_close"></a>
					        
					        
					        
					        <script type="text/javascript">

					        $(document).ready(function(){

					        	$("#msg_slideshow<?php echo $val['id'];?>").css("background","none");

					        });
					        
					        </script>
					         
					        
					    </div>
					</div>
					
					<!-- End !-->
				
				<!-- <span class="overlay"></span> !-->
			
			</div>
			
			
			
			<div class="clear"></div>
			
			<script type="text/javascript">



            $(function() {
				/**
				* interval : time between the display of images
				* playtime : the timeout for the setInterval function
				* current  : number to control the current image
				* current_thumb : the index of the current thumbs wrapper
				* nmb_thumb_wrappers : total number	of thumbs wrappers
				* nmb_images_wrapper : the number of images inside of each wrapper
				*/
				var interval			= 4000;
				var playtime;
				var current 			= 0;
				var current_thumb 		= 0;
				var nmb_thumb_wrappers	= $('#msg_thumbs<?php echo $val['id'];?> .msg_thumb_wrapper').length;
				
				var nmb_images_wrapper  = 6;
				/**
				* start the slideshow
				*/
				play();
				
				/**
				* show the controls when 
				* mouseover the main container
				*/

				<?php if(count($list) > 1):?>				
				
				slideshowMouseEvent();

				<?php endif; ?>

				function slideshowMouseEvent(){
					$('#msg_slideshow<?php echo $val['id'];?>').unbind('mouseenter')
									   .bind('mouseenter',showControls)
									   .andSelf()
									   .unbind('mouseleave')
									   .bind('mouseleave',hideControls);
					}
				
				/**
				* clicking the grid icon,
				* shows the thumbs view, pauses the slideshow, and hides the controls
				*/
				$('#msg_grid<?php echo $val['id'];?>').bind('click',function(e){
					hideControls();
					$('#msg_slideshow<?php echo $val['id'];?>').unbind('mouseenter').unbind('mouseleave');
					pause();
					$('#msg_thumbs<?php echo $val['id'];?>').stop().animate({'top':'0px'},500);
					e.preventDefault();
				});
				
				/**
				* closing the thumbs view,
				* shows the controls
				*/
				$('#msg_thumb_close<?php echo $val['id'];?>').bind('click',function(e){
					showControls();
					slideshowMouseEvent();
					$('#msg_thumbs').stop().animate({'top':'-230px'},500);
					e.preventDefault();
				});
				
				/**
				* pause or play icons
				*/
				$('#msg_pause_play<?php echo $val['id'];?>').bind('click',function(e){
					var $this = $(this);
					if($this.hasClass('msg_play'))
						play();
					else
						pause();
					e.preventDefault();	
				});
				
				/**
				* click controls next or prev,
				* pauses the slideshow, 
				* and displays the next or prevoius image
				*/
				$('#msg_next<?php echo $val['id'];?>').bind('click',function(e){
					pause();
					next();
					e.preventDefault();
				});
				$('#msg_prev<?php echo $val['id'];?>').bind('click',function(e){
					pause();
					prev();
					e.preventDefault();
				});
				
				/**
				* show and hide controls functions
				*/
				function showControls(){
					$('#msg_controls<?php echo $val['id'];?>').stop().animate({'right':'15px'},500);
				}
				function hideControls(){
					$('#msg_controls<?php echo $val['id'];?>').stop().animate({'right':'-110px'},500);
				}
				
				/**
				* start the slideshow
				*/
				function play(){


					next();

					$('#msg_pause_play<?php echo $val['id'];?>').addClass('msg_pause').removeClass('msg_play');
					playtime = setInterval(next,interval)
					
				}
				
				/**
				* stops the slideshow
				*/
				function pause(){
					$('#msg_pause_play<?php echo $val['id'];?>').addClass('msg_play').removeClass('msg_pause');
					clearTimeout(playtime);
				}
				
				/**
				* show the next image
				*/
				function next(){
					++current;
					showImage('r');
				}
				
				/**
				* shows the previous image
				*/
				function prev(){
					--current;
					showImage('l');
				}
				
				/**
				* shows an image
				* dir : right or left
				*/
				function showImage(dir){
					/**
					* the thumbs wrapper being shown, is always 
					* the one containing the current image
					*/
					alternateThumbs();
					
					/**
					* the thumb that will be displayed in full mode
					*/
					var $thumb = $('#msg_thumbs<?php echo $val['id'];?> .msg_thumb_wrapper:nth-child('+current_thumb+')')
								.find('a:nth-child('+ parseInt(current - nmb_images_wrapper*(current_thumb -1)) +')')
								.find('img');
					if($thumb.length){
						var source = $thumb.attr('alt');
						var $currentImage = $('#msg_wrapper<?php echo $val['id'];?>').find('img');
						if($currentImage.length){
							$currentImage.fadeOut(function(){
								$(this).remove();
								$('<img />').load(function(){
									var $image = $(this);
									resize($image);
									$image.hide();
									$('#msg_wrapper<?php echo $val['id'];?>').empty().append($image.fadeIn());
								}).attr('src',source);
							});
						}
						else{
							$('<img />').load(function(){
									var $image = $(this);
									resize($image);
									$image.hide();
									$('#msg_wrapper<?php echo $val['id'];?>').empty().append($image.fadeIn());
							}).attr('src',source);
						}
								
					}
					else{ //this is actually not necessary since we have a circular slideshow
						if(dir == 'r')
							--current;
						else if(dir == 'l')
							++current;	
						alternateThumbs();
						return;
					}
				}
				
				/**
				* the thumbs wrapper being shown, is always 
				* the one containing the current image
				*/
				function alternateThumbs(){
					$('#msg_thumbs<?php echo $val['id'];?>').find('.msg_thumb_wrapper:nth-child('+current_thumb+')')
									.hide();
					current_thumb = Math.ceil(current/nmb_images_wrapper);
					/**
					* if we reach the end, start from the beggining
					*/
					if(current_thumb > nmb_thumb_wrappers){
						current_thumb 	= 1;
						current 		= 1;
					}	
					/**
					* if we are at the beggining, go to the end
					*/					
					else if(current_thumb == 0){
						current_thumb 	= nmb_thumb_wrappers;
						current 		= current_thumb*nmb_images_wrapper;
					}
					
					$('#msg_thumbs<?php echo $val['id'];?>').find('.msg_thumb_wrapper:nth-child('+current_thumb+')')
									.show();	
				}
				
				/**
				* click next or previous on the thumbs wrapper
				*/
				$('#msg_thumb_next<?php echo $val['id'];?>').bind('click',function(e){
					next_thumb();
					e.preventDefault();
				});
				$('#msg_thumb_prev<?php echo $val['id'];?>').bind('click',function(e){
					prev_thumb();
					e.preventDefault();
				});
				function next_thumb(){
					var $next_wrapper = $('#msg_thumbs<?php echo $val['id'];?>').find('.msg_thumb_wrapper:nth-child('+parseInt(current_thumb+1)+')');
					if($next_wrapper.length){
						$('#msg_thumbs<?php echo $val['id'];?>').find('.msg_thumb_wrapper:nth-child('+current_thumb+')')
										.fadeOut(function(){
											++current_thumb;
											$next_wrapper.fadeIn();									
										});
					}
				}
				function prev_thumb(){
					var $prev_wrapper = $('#msg_thumbs<?php echo $val['id'];?>').find('.msg_thumb_wrapper:nth-child('+parseInt(current_thumb-1)+')');
					if($prev_wrapper.length){
						$('#msg_thumbs<?php echo $val['id'];?>').find('.msg_thumb_wrapper:nth-child('+current_thumb+')')
										.fadeOut(function(){
											--current_thumb;
											$prev_wrapper.fadeIn();									
										});
					}				
				}
				
				/**
				* clicking on a thumb, displays the image (alt attribute of the thumb)
				*/
				$('#msg_thumbs<?php echo $val['id'];?> .msg_thumb_wrapper > a').bind('click',function(e){
					var $this 		= $(this);
					$('#msg_thumb_close<?php echo $val['id'];?>').trigger('click');
					var idx			= $this.index();
					var p_idx		= $this.parent().index();
					current			= parseInt(p_idx*nmb_images_wrapper + idx + 1);
					showImage();
					e.preventDefault();
				}).bind('mouseenter',function(){
					var $this 		= $(this);
					$this.stop().animate({'opacity':1});
				}).bind('mouseleave',function(){
					var $this 		= $(this);	
					$this.stop().animate({'opacity':0.5});
				});
				
				/**
				* resize the image to fit in the container (400 x 400)
				*/
				function resize($image){
					var theImage 	= new Image();
					theImage.src 	= $image.attr("src");
					var imgwidth 	= theImage.width;
					var imgheight 	= theImage.height;
					
					var containerwidth  = 200;
					var containerheight = 200;
                
					if(imgwidth	> containerwidth){
						var newwidth = containerwidth;
						var ratio = imgwidth / containerwidth;
						var newheight = imgheight / ratio;
						if(newheight > containerheight){
							var newnewheight = containerheight;
							var newratio = newheight/containerheight;
							var newnewwidth =newwidth/newratio;
							theImage.width = newnewwidth;
							theImage.height= newnewheight;
						}
						else{
							theImage.width = newwidth;
							theImage.height= newheight;
						}
					}
					else if(imgheight > containerheight){
						var newheight = containerheight;
						var ratio = imgheight / containerheight;
						var newwidth = imgwidth / ratio;
						if(newwidth > containerwidth){
							var newnewwidth = containerwidth;
							var newratio = newwidth/containerwidth;
							var newnewheight =newheight/newratio;
							theImage.height = newnewheight;
							theImage.width= newnewwidth;
						}
						else{
							theImage.width = newwidth;
							theImage.height= newheight;
						}
					}
					$image.css({
						'width'	:theImage.width,
						'height':theImage.height
					});
				}
            });

            

			//***************

//////////////////////////////////////////////////////////////////////////////////
            // Cloud Zoom V1.0.2
            // (c) 2010 by R Cecco. <http://www.professorcloud.com>
            // MIT License
            //
            // Please retain this copyright header in all versions of the software
            //////////////////////////////////////////////////////////////////////////////////
            

            $(function() {
				/*
				fancybox init on each cloud-zoom element
				 */
				$("#content<?php echo $val['id'];?> .cloud-zoom").fancybox({
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'none',
					'speedIn'		:	600,
					'speedOut'		:	200,
					'overlayShow'	:	true,
					'overlayColor'	:	'#000',
					'cyclic'		:	true,
					'easingIn'		:	'easeInOutExpo'
				});

				/*
				because the cloud zoom plugin draws a mousetrap
				div on top of the image, the fancybox click needs
				to be changed. What we do here is to trigger the click
				the fancybox expects, when we click the mousetrap div.
				We know the mousetrap div is inserted after
				the <a> we want to click:
				 */
				$("#content<?php echo $val['id'];?> .mousetrap").live('click',function(){
					$(this).prev().trigger('click');
				});

				/*
				the content element;
				each list item / group with several images
				 */
				var $content	= $('#content<?php echo $val['id'];?>'),
				$thumb_list = $content.find('.thumb > ul');
				/*
				we need to set the width of each ul (sum of the children width);
				we are also defining the click events on the right and left arrows
				of each item.
				 */
				$thumb_list.each(function(){
					var $this_list	= $(this),
					total_w		= 0,
					loaded		= 0,
					//preload all the images first
					$images		= $this_list.find('img'),
					total_images= $images.length;
					$images.each(function(){
						var $img	= $(this);
						$('<img/>').load(function(){
							++loaded;
							if (loaded == total_images){
								$this_list.data('current',0).children().each(function(){
									total_w	+= $(this).width();
								});
								$this_list.css('width', total_w + 'px');

								//next / prev events

								$this_list.parent()
								.siblings('.next')
								.bind('click',function(e){
									var current = $this_list.data('current');
									if(current == $this_list.children().length -1) return false;
									var	next	= ++current,
									ml		= -next * $this_list.children(':first').width();

									$this_list.data('current',next)
									.stop()
									.animate({
										'marginLeft'	: ml + 'px'
									},400);
									e.preventDefault();
								})
								.end()
								.siblings('.prev')
								.bind('click',function(e){
									var current = $this_list.data('current');
									if(current == 0) return false;
									var	prev	= --current,
									ml		= -prev * $this_list.children(':first').width();

									$this_list.data('current',prev)
									.stop()
									.animate({
										'marginLeft'	: ml + 'px'
									},400);
									e.preventDefault();
								});
							}
						}).attr('src',$img.attr('src'));
					});
				});
			});
            
 </script>
			
		<?php endif;?>		
					
		</div>
				
				
				
				<?php $listcomment = $this->comment->listItemByPost($val["id"],$this->pagecomment,$this->pagesizecomment);?>
				
				
				
				<div>
					
					
					<span class="video-extras-likes-dislikes" id="like<?php echo $val["id"];?>">
						<?php if ($data == FALSE || ($data && $this->like->ischeckLike($val["id"],$data->id)) == 0):?>
      					<a href="javascript:void(0);" onclick="<?php if($data):?>like('post','like','<?php echo $val["id"];?>'); return false; <?php else:?> login();  <?php endif;?>"><img class="icon-watch-stats-like" src="//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="Thích"></a>
      					
      					<?php else :?>
      					
      					<a href="javascript:void(0);" ><img class="icon-watch-stats-like" src="//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="Thích"></a>
      					
      					<?php endif;?>
      					
      					
      					<?php if($this->like->countLike($val["id"],"like") > 0): ?>
  							<span class="likes-count"><?php echo $this->like->countLike($val["id"],"like");?></span>
  						<?php endif;?>
  						<!-- 
 						&nbsp;&nbsp;&nbsp;  
 						 <img class="icon-watch-stats-dislike" src="//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="Không thích">
  						<span class="dislikes-count"><?php echo $this->like->countLike($val["id"],"dislike");?></span>
  						!-->
  					</span>
  					
  					
  					<span id="liked<?php echo $val["id"];?>" style="display:none; font-size: 11px;">
						Bạn đã thích 
					</span>
				</div>
				
				<div id="comment-box<?php echo $val["id"];?>">
				
				<?php $totalcomment =  $this->comment->countPost($val["id"]);?>
				
					<h4>
					<?php if ($totalcomment>0):?>
						<?php echo $totalcomment;?>
					<?php endif;?>
					
					Bình luận
					</h4>
					
					<ol class="commentlist clearfix">
					
					<?php foreach( $listcomment as $key => $item):?>
					
						<?php $user = $this->auth->getItemByComment($item["userid"]);?>
					
						<li class="comment">
						
							<div class="clearfix">
							
								<div class="avatar">
								
									<?php if(isset($user["avatar"])):?>
			
										<img alt="noavatar" style="width: 40px; height: 40px;" src="<?php echo $url;?>/upload/<?php echo $user["avatar"];?>">
										
									<?php else :?>
										<img alt="noavatar" style="width: 40px; height: 40px;" src="<?php echo $url;?>/upload/noavatar.gif">
									<?php endif;?>			
									<span class="overlay"></span>									
								</div>
								
								<div class="comment-wrap">
								
								
								<div class="comment-author vcard">
									
									<h4><?php echo $user["displayname"];?></h4>
									
								</div>
								
								<div class="comment-content">
								<p><?php echo $item["content"]?></p>
								</div>
								
								</div>
								
							</div>
						
						</li>
						
					<?php endforeach;?>
					
					</ol>
					<div class="yt-uix-pager" id="comment-show" role="navigation" style="text-align: center;">
				    	<input type="hidden" id="idpost<?php echo $val["id"]?>" value="<?php echo $val["id"]?>" >    
				    	<input type="hidden" id="pagecomment<?php echo $val["id"]?>" value="<?php echo $this->pagecomment+1;?>" >     
				    	<input type="hidden" id="pagesizecomment<?php echo $val["id"]?>" value="<?php echo $this->pagesizecomment;?>" >
				    	<input type="hidden" id="totalcomment<?php echo $val["id"]?>" value="<?php echo $this->comment->countPost($val["id"]);?>" >
				    	<div id="wait-load-comment<?php echo $val["id"]?>">
				    	</div>
						<a id="show-comment<?php echo $val["id"]?>" href="javascript:void(0);" onclick="loadComment('pagecomment<?php echo $val["id"]?>','pagesizecomment<?php echo $val["id"]?>','totalcomment<?php echo $val["id"]?>','idpost<?php echo $val["id"]?>');"><span class="yt-uix-button-content">Hiển thị thêm</span></a>
				    </div>
				    
				    <script type="text/javascript">

						$(document).ready(function(){
				
							var page = parseInt($("#pagecomment<?php echo $val["id"]?>").val());
							var pagesize = parseInt($("#pagesizecomment<?php echo $val["id"]?>").val());
							var total = parseInt($("#totalcomment<?php echo $val["id"]?>").val());
							
							if ((page-1)*pagesize >= total){
				
								$("#show-comment<?php echo $val["id"]?>").css("display","none");
								
							}
									
						});
									
									
					</script>
				
				
				</div>
				
				
				
				<div>
				
					<ol class="commentlist clearfix">
					
						<li class="comment">
						
								<div class="clearfix">
							
								
							
								<div class="avatar">
									<?php if(isset($data->avatar)):?>
			
										<img alt="noavatar" style="width: 40px; height: 40px;" src="<?php echo $url;?>/upload/<?php echo $data->avatar;?>">
										
									<?php else :?>
										<img alt="noavatar" style="width: 40px; height: 40px;" src="http://0.gravatar.com/avatar/98d7a2361501957b551a32fceca493a5?s=56&d=mm&r=G">
									<?php endif;?>
													
									<span class="overlay"></span>									
								</div>
								
								<div class="comment-wrap">
								
								<div class="comment-content">
								<div id="wait-load<?php echo $val["id"];?>"></div>
								<p>
									<textarea id="comment<?php echo $val["id"];?>"  placeholder="Viết bình luận"></textarea>
									
									<script type="text/javascript">

									$(document).ready(function(){
										
										$('#comment<?php echo $val["id"];?>').bind('keypress', function(e) {
											
											<?php if ($data):?>

												if(e.keyCode==13){	
													insertComment('<?php echo $val["id"];?>');													
												}											

											<?php else:?>

												login();
																								
											<?php endif;?>

										});
									
									});
									
									
									</script>
									
								</p>
								</div>
								
								</div>
								
							</div>							
						
						</li>
						</ol>
				</div>
			
		</div>
		
		
	</div>

</div>

<?php endforeach;?>


</div>

<div id="post-show" class="post" style="background:none; border:none; box-shadow:none;padding-top: 0px;">

	<div class="post-content clearfix" style="background: none; min-height: auto;">

		<div class="comments-pagination" data-ajax-enabled="true" style="text-align:center;">

    <div class="yt-uix-pager" role="navigation">
    
    	
    	<div id="wait-load"></div>
    	
		<?php if($this->categoryid):?>
		
		<input type="hidden" id="categoryid" value="<?php echo $this->categoryid;?>" >
		
		<?php else :?>
		
		<input type="hidden" id="categoryid" value="" >
		
		<?php endif;?>
		
		<input type="hidden" id="page" value="<?php echo $this->page;?>" >     
	    <input type="hidden" id="pagesize" value="<?php echo $this->pagesize;?>" >
	    <input type="hidden" id="total" value="<?php echo $this->total;?>" >
		<a id="show-post" href="javascript:void(0)" class="btn yt-uix-button-show" onclick="loadPostHome('page','pagesize','total','categoryid');"><span class="yt-uix-button-content">Hiển thị thêm</span></a>
    </div>
	</div>
	</div>
</div>



<script type="text/javascript">

	$(document).ready(function(){

		$(".small").css("width","209px");
		$(".thumbnail").css("width","200px");
		$(".thumbnail").css("height","230px");		
		$(".msg_slideshow").css("background","none");
		$(".msg_slideshow").css("padding-left","0px");

		var page = parseInt($("#page").val());
		var pagesize = parseInt($("#pagesize").val());
		var total = parseInt($("#total").val());

		
		
		if ((page-1)*pagesize >= total){

			
			
			$("#show-post").css("display","none");
			
		}

		//loadRss("Car","rssvnexpress@vnexpress.com");
		
	});

</script>